package com.zhugang.week02;

/**
 * @program algorithms
 * @description: arrayList
 * @author: chanzhugang
 * @create: 2022/04/17 21:55
 */
public class MyArrayList {

    public int[] data;
    public int n = 10;
    public int count = 0;

    public MyArrayList(int n) {
        data = new int[n];
    }

    public void add(int element) {
        // 扩容
        if (count == n) {
            int[] newData = new int[n * 2];
            for (int i = 0; i < n; i++) {
                newData[i] = data[i];
            }
            n *= 2;
            data = newData;
        }
        data[count] = element;
        count++;
    }

}